/*
 * Page.java
 *
 * Generic www page
 * Include menu.
 */

package net.kernub.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.client.ui.VerticalPanel;

import net.kernub.client.HeaderPanel;

/*
 * Doc:
 *
 * A Page is composed of:
 *	- page parts, which are static and are always present
 *	- page content, the muttable part of the page, which is changing
 */

/*
 * Page class
 */
public class Page
{
	private static boolean isInitialize = false;

	private static final VerticalPanel pagePanel = new VerticalPanel();

	private static final HeaderPanel headerPanel = new HeaderPanel();
	//private static Widget content = null;

	private static Widget currentContent = null;

	private Widget mainContent = null;

	public Page()
	{
		//GWT.log( "Page::Page() try initializing", null );
		if( isInitialize ) return;

		pagePanel.setWidth( "100%" );
		pagePanel.add( headerPanel );

		isInitialize = true;

		//GWT.log( "Page::Page() initialized", null );
	}

	// to overload, called when the page is active
	public void setActive()
	{
		if( currentContent != null )
		{
			pagePanel.remove( currentContent );
		}
		pagePanel.add( mainContent );
		currentContent = mainContent;
	}

	public Widget getWidget()
	{
		return pagePanel;
	}

	protected void setContent( Widget content )
	{
		mainContent = content;
	}

	protected void addPagePart( Widget part )
	{
		pagePanel.add( part );
	}

	protected void setTempInfo( String text )
	{
		headerPanel.setTempInfo( text );
	}

	public void showLoading()
	{
		headerPanel.showLoading();
	}

	public void hideLoading()
	{
		headerPanel.hideLoading();
	}
}

